<!-- Modal -->
<div class="modal fade " id="addInstitutionModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document" style="width: 70%">
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">机构基本信息</h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form class="form-horizontal">
                <div class="box-body">
                    <div class="form-group">
                        <label class="col-sm-2 control-label"><span style="color:red">*</span>机构名称：</label>
                        <div class="col-sm-3">
                            <input id="addInstitutionModal_name" type="text" class="form-control"
                                   style="width: 100%;">
                            <input id="addInstitutionModal_institutionId" type="hidden">
                            <input id="addInstitutionModal_inde" type="hidden">
                        </div>
                        <label class="col-sm-2 control-label">市场部对接人：</label>
                        <div class="col-sm-3"><select class="form-control select2" style="width: 100%;"  id="addInstitutionModal_picUserId"></select>
                        </div>

                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"><span style="color:red">*</span>机构简称：</label>
                        <div class="col-sm-3">
                            <input id="addInstitutionModal_shortName" type="text" class="form-control"
                                   style="width: 100%;">
                        </div>
                        <label class="col-sm-2 control-label"><span style="color:red">*</span>机构类型：</label>
                        <div class="col-sm-3">
                            <select class="form-control select2" style="width: 100%;"
                                    id="addInstitutionModal_businessType">
                                <option>请选择</option>
                                <option value="1">寿险</option>
                                <option value="2">财险</option>
                                <option value="3">年金</option>
                                <option value="4">银行</option>
                                <option value="5">健康险</option>
                                <option value="6">华泰</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"><span style="color:red">*</span>股东背景：</label>
                        <div class="col-sm-3">
                            <select class="form-control select2" style="width: 100%;"
                                    id="addInstitutionModal_shareholderBg">
                                <option>请选择</option>
                                <option value="1">中资</option>
                                <option value="2">外资</option>
                                <option value="3">银行系</option>
                            </select>
                        </div>
                        <label for="inputEmail3" class="col-sm-3 control-label pull-left">上年保费收入规模（亿元）：</label>
                        <div class="col-sm-2">
                            <input id="addInstitutionModal_premiumsIncome" type="text" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputEmail3" class="col-sm-2 control-label pull-left">债权直投资格：</label>
                        <div class="col-sm-3">
                            <select class="form-control select2" style="width: 100%;"
                                    id="addInstitutionModal_isHasInvestQualif">
                                <option>请选择</option>
                                <option value="1">有</option>
                                <option value="0">无</option>
                            </select>
                        </div>
                        <label for="inputEmail3" class="col-sm-2 control-label pull-left">投资通道机构：</label>
                        <div class="col-sm-3">
                            <input id="addInstitutionModal_channelInstitution" type="text" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"><span style="color:red">*</span>地址：</label>
                        <div class="col-sm-2">
                            <select class="form-control select2" style="width: 100%;" id="addInstitutionModal_province"
                                    onchange="addInstitutionModal_refreshCity()">
                            </select>
                        </div>
                        <div class="col-sm-2">
                            <select class="form-control select2" style="width: 100%;" id="addInstitutionModal_city">
                            </select>
                        </div>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" id="addInstitutionModal_address">
                        </div>
                    </div>

                    <div class="form-group">

                    </div>
                </div>
                <!-- /.box-body -->
                <div class="box-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button id="btnSubmit" type="button" class="btn btn-primary pull-right"
                            onclick="addInstitutionModal_save()">保存
                    </button>
                </div>
                <!-- /.box-footer -->
            </form>
        </div>
    </div>
</div>

<script>
    function addInstitutionModal_refreshCity() {
        var provinceId = $("#addInstitutionModal_province").val();
        var url = "/public/address/list?parentId=" + provinceId;
        $("#addInstitutionModal_city").empty();
        setFormValue(url, "addInstitutionModal_city");
    }

    function addInstitutionModal_Init() {
        $("#addInstitutionModal_institutionId").val("");
        $("#addInstitutionModal_inde").val("");
        $("#addInstitutionModal_name").val("");
        $("#addInstitutionModal_shortName").val("");
        $("#addInstitutionModal_businessType").val("");
        $("#addInstitutionModal_shareholderBg").val("");
        $("#addInstitutionModal_premiumsIncome").val("");
        $("#addInstitutionModal_isHasInvestQualif").val("");
        $("#addInstitutionModal_channelInstitution").val("");
        $("#addInstitutionModal_address").val("");
        $("#addInstitutionModal_picUserId").empty();
        $("#addInstitutionModal_province").empty();
        $("#addInstitutionModal_city").empty();
    }

    function addInstitutionModal_SetValue(inde) {
        var url1 = "/institution/saleuserlist";
        var url2 = "/public/address/list";
        if(inde == -1 ) {
            setFormValue(url1, "addInstitutionModal_picUserId");
            setFormValue(url2, "addInstitutionModal_province");
        } else {
            var options = $("#table1").bootstrapTable("getData");
            var row = options[inde];
            $("#addInstitutionModal_inde").val(inde);
            $("#addInstitutionModal_institutionId").val(row.id);
            $("#addInstitutionModal_name").val(row.name);
            $("#addInstitutionModal_shortName").val(row.shortName);
            $("#addInstitutionModal_businessType").select2("val",row.businessType);
            $("#addInstitutionModal_shareholderBg").select2("val",row.shareholderBg);
            $("#addInstitutionModal_premiumsIncome").val(row.premiumsIncome);
            $("#addInstitutionModal_isHasInvestQualif").select2("val",row.isHasInvestQualif);
            $("#addInstitutionModal_channelInstitution").val(row.channelInstitution);
            $("#addInstitutionModal_address").val(row.address);

            setFormValue(url1, "addInstitutionModal_picUserId",row.picUserId);
            setFormValue(url2, "addInstitutionModal_province",row.province);

            var url3 =  "/public/address/list?parentId=" + row.province ;
            setFormValue(url3, "addInstitutionModal_city",row.city);
        }
    }


    function addInstitutionModal_save() {
        var name = $("#addInstitutionModal_name").val();
        if(name == "" || undefined == name ) {
            toastr['error']('请输入机构名称', '提示');
            $("#addInstitutionModal_name").focus();
            return;
        }
        var shortName = $("#addInstitutionModal_shortName").val();
        if(shortName == "" || undefined == shortName ) {
            toastr['error']('请输入机构简称', '提示');
            $("#addInstitutionModal_shortName").focus();
            return;
        }
        var businessType = $("#addInstitutionModal_businessType").val();
        if(businessType == "" || undefined == businessType ) {
            toastr['error']('请输入机构类型', '提示');
            $("#addInstitutionModal_businessType").focus();
            return;
        }
        var shareholderBg = $("#addInstitutionModal_shareholderBg").val();
        if(shareholderBg == "" || undefined == shareholderBg ) {
            toastr['error']('请输入股东背景', '提示');
            return;
        }
        var province = $("#addInstitutionModal_province").val();
        if(province == "" || undefined == province ) {
            toastr['error']('请输入省份', '提示');
            return;
        }
        var city = $("#addInstitutionModal_city").val();
        if(city == "" || undefined == city ) {
            toastr['error']('请输入城市', '提示');
            return;
        }
        var picUserId = $("#addInstitutionModal_picUserId").val();
        var premiumsIncome = $("#addInstitutionModal_premiumsIncome").val();
        var isHasInvestQualif = $("#addInstitutionModal_isHasInvestQualif").val();
        var channelInstitution = $("#addInstitutionModal_channelInstitution").val();
        var address = $("#addInstitutionModal_address").val();
        var data = {
            id: $("#addInstitutionModal_institutionId").val(),
            name: name,
            picUserId: picUserId,
            shortName: shortName,
            businessType:businessType,
            shareholderBg: shareholderBg,
            premiumsIncome: premiumsIncome,
            isHasInvestQualif: isHasInvestQualif,
            channelInstitution: channelInstitution,
            province: province,
            city: city,
            address:address
        };
        var url = "/institution/save";
        postReq(url, data, function (result) {
            if (result.success) {
                toastr['success']('操作成功', '提示');
                $("#table1").bootstrapTable("refresh");
                $("#addInstitutionModal").modal("hide");
            } else {
                toastr['error'](result.msg, '提示');
            }
        });
    }
</script>
